package utils;

import controller.DBUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class Select extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=utf-8");
        req.setCharacterEncoding("utf-8");
        Statement statement = null;
        ResultSet resultSet = null;
        Connection connection = null;
        try {
            connection = DBUtils.Connection();
            statement = connection.createStatement();
            resultSet = statement.executeQuery("SELECT cloth_name from clothes where cloth_name LIKE '"+"%" + req.getParameter("str") + "%'");
//            System.out.println(req.getParameter("str"));
            
            String se = "";
            while(resultSet.next()){
                se += resultSet.getString(1)+"<br>";
               // System.out.println(se);
            }
            resp.getWriter().write(se);
//            req.setAttribute("abc",se);
//            req.getRequestDispatcher("/servlet").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
